package com.xitang.system.poi;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.xitang.common.bean.BizCategoryProduct;
import com.xitang.common.mapper.BizCategoryProductMapper;

import java.util.Map;

public class BizCategoryProductExcelListener extends AnalysisEventListener<BizCategoryProduct> {

    private BizCategoryProductMapper categoryProductMapper;

    public BizCategoryProductExcelListener(BizCategoryProductMapper categoryProductMapper) {
        this.categoryProductMapper = categoryProductMapper;
    }

    // 逐行读取excel内容
    @Override
    public void invoke(BizCategoryProduct categoryProduct, AnalysisContext analysisContext) {
        System.out.println("excel内容：" + categoryProduct);
        categoryProductMapper.insert(categoryProduct);
    }

    // 读取excel表头信息
    @Override
    public void invokeHeadMap(Map<Integer, String> headMap, AnalysisContext context) {
        System.out.println("表头：" + headMap);
    }

    // 读取完之后执行
    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
        System.out.println("end");
    }
}
